package com.srit.identify.common.interceptor;

import com.srit.identify.common.utils.JwtUtil;
import io.jsonwebtoken.Claims;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//登录拦截器
@Component
public class TokenInterceptor implements HandlerInterceptor {

    @Autowired

    public static final String HEADER_AUTH = "authorization";


    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)  {
        String token = request.getHeader(HEADER_AUTH);
        try {
            Claims claims = JwtUtil.validateToken(token);
        }catch (Exception e) {
            System.out.println(false);
            return false;
        }
        System.out.println(true);
        return true;
    }
}
